package cn.dapeng.features;

import cn.dapeng.util.SleepingUtil;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
 * unpark可以先于park前调用
 *
 */
public class LockSupport_T01 {

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                if(i == 5) {
                    LockSupport.park();
                }
                System.out.println(i);
                SleepingUtil.sleep(1, TimeUnit.SECONDS);
            }
        });

        t1.start();

        SleepingUtil.sleep(10, TimeUnit.SECONDS);
        LockSupport.unpark(t1);
    }
}
